package cn.geoportal.benoserver.service.impl;

import cn.geoportal.benoserver.entity.vo.shpload.ShploadAdd;
import cn.geoportal.benoserver.entity.vo.shpload.ShploadGet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.geoportal.benoserver.entity.ShploadTask;
import cn.geoportal.benoserver.service.ShploadTaskService;
import cn.geoportal.benoserver.mapper.ShploadTaskMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class ShploadTaskServiceImpl extends ServiceImpl<ShploadTaskMapper, ShploadTask>
implements ShploadTaskService{

    @Autowired
    private ShploadTaskMapper shploadTaskMapper;

    @Override
    public IPage<ShploadTask> queryShploadPage(Page<ShploadTask> page, QueryWrapper<ShploadTask> wrapper) {
        return shploadTaskMapper.queryShploadPage(page, wrapper);
    }

    @Override
    public int add(ShploadAdd shploadAdd) {
        QueryWrapper<ShploadTask> wrapper = new QueryWrapper<>();
        wrapper.eq("name", shploadAdd.getName());
        if(shploadTaskMapper.selectCount(wrapper)>0){
            return 0;
        }
        return shploadTaskMapper.addShploadTask(shploadAdd.getName(), shploadAdd.getDescription(), shploadAdd.getDbid(),
                shploadAdd.getShpfile(), shploadAdd.getEpsg(), shploadAdd.getStatus());
    }

    @Override
    public ShploadGet getShploadTaskById(Integer id) {
        return shploadTaskMapper.getShploadById(id);
    }

    @Override
    public int updateShploadTask(ShploadTask shploadTask) {
        return shploadTaskMapper.updateById(shploadTask);
    }

    @Override
    public int deleteShploadTask(Integer id) {
        return shploadTaskMapper.deleteById(id);
    }
}




